import type { ServerOptions } from "vite";

export function createServer(mode: string, envs: Record<string, string>): ServerOptions {
  const { VITE_APP_API } = envs;
  return {
    proxy: {
      // with options: http://localhost:5173/proxy/bar-> {{VITE_APP_API}}/bar
      "/proxy": {
        target: VITE_APP_API,
        rewrite: path => path.replace(/^\/proxy/, ""),
        changeOrigin: true, // 开启代理，在本地创建一个虚拟服务端
        // secure: true,
        secure: false,
        // ws:true  //开始websocket 代理
      },
    },
    port: 8080,
    host: "0.0.0.0",
    https: null,
  };
}
